package leetcode_core.leetcode_1;

import org.junit.Test;

public class Rob4 {
    private int helper(int[] nums,int start,int end){
        int[] dp = new int[nums.length+2];
        dp[end+1] = 0;
        for(int i = end;i>=start;i--){
            dp[i] = Math.max(
                    dp[i+2]+nums[i],
                    dp[i+1]
            );
        }
        return dp[start];
    }

    public int rob(int[] nums) {
        if(nums.length == 1){
            return nums[0];
        }
        return Math.max(helper(nums,0,nums.length-2),helper(nums,1,nums.length-1));//是否选择拿第一间房子的钱
    }

    @Test
    public void testCaseOne(){
        System.out.println(rob(new int[]{1, 2, 3,1}));
    }
    @Test
    public void testCaseTwo(){
        System.out.println(rob(new int[]{1,2,3}));
    }

}
